<?
	layout("/inc/layout.html",{title:sysTitle}){
?>

<div id="page-wrapper">
	<!--BEGIN TITLE & BREADCRUMB PAGE-->
	<div id="title-breadcrumb-option-demo" class="page-title-breadcrumb">
		<div class="page-header pull-left">
			<div class="page-title">索引管理</div>
		</div>
		<ol class="breadcrumb page-breadcrumb pull-left">
			<li><i class="fa fa-home"></i>&nbsp;<a href="main.html">首页</a>&nbsp;&nbsp;<i
				class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li>统一检索管理&nbsp;&nbsp;<i class="fa fa-angle-right"></i>&nbsp;&nbsp;</li>
			<li class="active">索引管理</li>
		</ol>

		<div class="clearfix"></div>
	</div>
	<!--END TITLE & BREADCRUMB PAGE-->
	<!--BEGIN CONTENT-->
	<div class="page-content">

		<!-- 索引管理界面 start -->
		<div class="row">
			<div class="col-lg-12">
				<div class="note note-danger">
					<h3 class="box-heading">#知识库索引管理</h3>
				</div>
			</div>
		</div>
		<div class="row" id="KnowledgeData">
           
        </div>
        
        <div class="row">
			<div class="col-lg-12">
				<div class="note note-danger">
					<h3 class="box-heading">#支撑系统索引管理</h3>
				</div>
			</div>
		</div>
		<div class="row">
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">知识百科（baike）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;" id="mysqlBaikeCount">
                    		仓储库数据总量（百科词条）：99999
                    </p>
                    	<p style="font-size: 15px;" id="solrBaikeCount">
                    		索引库数据总量（百科词条）：99999
                    	</p>
                    	<p>
                    		<button class="btn btn-sm btn-primary" onclick="deleteSolrAllIndexes('baike','')">清空全库索引</button>
                    		<button class="btn btn-sm btn-grey" onclick="toSolrExpression('baike')">按表达式清空索引</button>
                    	</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">知识词表（word）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;" id="mysqlWordCount">
                    		仓储库数据总量（普通词表+叙词表）：99999
                    </p>
                    	<p style="font-size: 15px;" id="solrWordCount">
                    		索引库数据总量（普通词表+叙词表）：99999
                    	</p>
                    	<p>
                    		<button class="btn btn-sm btn-primary" onclick="deleteSolrAllIndexes('word','')">清空全库索引</button>
                    		<button class="btn btn-sm btn-grey" onclick="toSolrExpression('word')">按表达式清空索引</button>
                    	</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">关键词库（keywords）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;" id="mysqlKeywordsCount">
                    		仓储库数据总量：0
                    </p>
                    	<p style="font-size: 15px;" id="solrKeywordsCount">
                    		
                    	</p>
                    	<p>
                    		<button class="btn btn-sm btn-primary" onclick="deleteSolrAllIndexes('keywords','')">清空全库索引</button>
                    		<button class="btn btn-sm btn-grey" onclick="toSolrExpression('keywords')">按表达式清空索引</button>
                    	</p>
                    </div>
                </div>
            </div>
            <div class="col-lg-4">
                <div class="panel">
                    <div class="panel-heading clearfix"><span class="mts pull-left">自动标引库（indexWeight）</span>
                    </div>
                    <div class="panel-body">
                    <p style="font-size: 15px;" id="mysqlIndexWeightCount" >
                    		仓储库数据总量：0
                    </p>
                    	<p style="font-size: 15px;" id="solrIndexWeightCount" >
                    		
                    	</p>
                    	<p>
                    		<button class="btn btn-sm btn-primary" onclick="deleteSolrAllIndexes('indexWeight','')">清空全库索引</button>
                    		<button class="btn btn-sm btn-grey" onclick="toSolrExpression('indexWeight')">按表达式清空索引</button>
                    	</p>
                    </div>
                </div>
            </div>
          </div>
		<!-- 索引管理界面 end -->
	</div>
	<!--END CONTENT-->
</div>
 <div id="box1" onclick="qingSolrData();" contenteditable="plaintext-only" style="border-style:solid; border-width:1px; border-color:#000;height: 330px;margin-top: 9px;margin-left: 9px;margin-right: 9px;display: none;">
 </div>	

<?} ?>
<script type="text/javascript">
	$(function() {
		demoKnowledge();
		getRestsSolrData();
	});
	function demoKnowledge() {
		$.ajax({
			type : "post",
			url : "getKnowledgeClassesSolrData.do",
			data : {},
			dataType : "json",
			traditional : true,
			success : function(data) {
				//alert(JSON.stringify(data));
				//此处仅仅是为了演示变化的内容
				var str = "";
				for ( var i = 0; i < data.length; i++) {
					str +='<div class="col-lg-4">'
                		+'<div class="panel">'
                   		+'<div class="panel-heading clearfix"><span class="mts pull-left">'+data[i].nameZh+'（'+data[i].nameEn+'）</span>'
                   		+'</div>'
                   		+'<div class="panel-body">'
                   		+'<p style="font-size: 15px;">'
                   		+'仓储库数据总量：'+data[i].dynamicCount
                   		+'</p>'
                   		+'<p style="font-size: 15px;">'
                   		+'索引库数据总量：'+data[i].searchFacet
                   		+'</p>'
                   		+'<p>'
                   		+'<button class="btn btn-sm btn-primary" onclick="deleteSolrAllIndexes(\'Knowledge\',\''+data[i].nameEn+'\')">清空全库索引</button>&nbsp;&nbsp;'
                   		+'<button class="btn btn-sm btn-grey" onclick="toSolrExpression(\'Knowledge\')">按表达式清空索引</button>'
                   		+'</p>'
                   		+'</div>'
                   		+'</div>'
                   		+'</div>';
				}
				$("#KnowledgeData").html(str);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
	function getRestsSolrData() {
		$.ajax({
			type : "post",
			url : "getRestsSolrData.do",
			data : {},
			dataType : "json",
			traditional : true,
			success : function(data) {
				//此处仅仅是为了演示变化的内容
				$("#mysqlBaikeCount").html("仓储库数据总量："+data[0].BaikeEntryCount);
				$("#solrBaikeCount").html("索引库数据总量："+data[0].solrbaikeCount);
				
				$("#mysqlWordCount").html("仓储库数据总量："+data[0].wordCount);
				$("#solrWordCount").html("索引库数据总量："+data[0].solrwordCount);
				
				$("#solrKeywordsCount").html("索引库数据总量："+data[0].solrkwCount);
				
				$("#solrIndexWeightCount").html("索引库数据总量："+data[0].solrindexingCount);
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
	//删除全部
	function deleteSolrAllIndexes(type,classesEn) {
		$.ajax({
			type : "post",
			url : "deleteSolrAllIndexes.do",
			data : {
				"type":type,
				"classesEn":classesEn,
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				//此处仅仅是为了演示变化的内容
				if(data[0].data == 'yes'){
					layer.msg('删除成功！');
					demoKnowledge();
					getRestsSolrData();
				}else{
					layer.msg('删除失败！');
				}
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
	function toSolrExpression(type){
		$("#box1").html("请按规范书写，例如：id:1   或  stringIS_title:\"张三\" AND (intIS_year:2016 OR intIS_year:2017)");
		layer.open({
		    type : 1,
			area : [ '500px', '450px' ],
			fix : false, //不固定
			scrollbar : false,
			shadeClose : true,
			move : false,
			title : '表达式',
			skin : 'layui-layer-rim', //加上边框
			btn : [ '保存 ', '关闭' ],
			content :$("#box1"),
			yes: function(){
				var solrdata =  $("#box1").html();
				deleteSolrIndexes(type,solrdata);
	 	      	layer.closeAll();
	 	    },
			cancel : function(index) {
			}
		});
	}
	function qingSolrData(){
		$("#box1").html("");
	}
 /* 	var d = document.getElementById( "box1" );
    document.addEventListener( "keyup", function() {
        d.innerHTML = d.innerHTML.replace( /<[^>]*>/g, "" );
    } ); */
  	//条件删除
	function deleteSolrIndexes(type,queryStr) {
		$.ajax({
			type : "post",
			url : "deleteSolrIndexes.do",
			data : {
				"type":type,
				"queryStr":queryStr,
			},
			dataType : "json",
			traditional : true,
			success : function(data) {
				//此处仅仅是为了演示变化的内容
				if(data[0].data == 'yes'){
					layer.msg('删除成功！');
					demoKnowledge();
					getRestsSolrData();
				}else{
					layer.msg('删除失败！');
				}
				
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	};
</script>